package com.duartepeixinho.P3D.ViewPort
{
	import com.duartepeixinho.P3D.Core.Math.Vector3;
	import flash.geom.Point;
	/**
	 * P3D
	 * @version 0.1
	 * @author Duarte Peixinho
	 */
	public class ViewPort
	{
		
		private var _width:Number;
		private var _height:Number;
		private var _focalLength:Number;
		private var _vpX:Number;
		private var _vpY:Number;
		
		public function ViewPort(width:Number = 800, height:Number = 600, focalLenght:Number = 500):void  
		{
			_width = width;
			_vpX = _width / 2;
			_height = height;
			_vpY = height / 2;
			_focalLength = focalLenght;
		}
		
		public function convert3Dto2D(vector:Vector3):Point {			
			var scaleFactor:Number = _focalLength / (_focalLength + vector.z);

			var point:Point = new Point();
			point.x = vector.x * scaleFactor + _vpX;
			// Invert Y Axis
			point.y = -vector.y * scaleFactor + _vpY;
			
			return point;
		}
		
		public function getScaleFactor(vector:Vector3):Number {
			return _focalLength / (_focalLength + vector.z);
		}
		
	}

}